package app.netant.galgame.hgamecn;

import cn.lily.com.db.sql.manager.DBOfflineManager;
import cn.lily.com.lang.number.MathUtil;

/**
 * 数据库操作实体类
 * @author JiaJ
 * @date 2018年6月13日
 *
 */
public class HgamecnEntity {
	
	private String gameName = "";
	
	private String gameMemo = "";
	
	private String gameFactory = "";
	
	private String gameDate = "1000-01-01";
	
	private String gamePic = "";
	
	private String gameWriter = "";
	
	private String gameTags = "";
	
	private String gameUrl = "";
	
	private boolean gameIsMemo = false;
	
	private String gameCast = "";
	private String gameMusic = "";
	private String gameSinger = "";
	private String gameOtherName = "";

	public void setGameName(String gameName) {
		this.gameName = gameName;
	}

	public void setGameUrl(String gameUrl) {
		this.gameUrl = gameUrl;
	}

	public void setGameMemo(String gameMemo) {
		
		if(gameMemo.length()>1300){
			gameMemo = gameMemo.substring(0,1300)+"......";
		}
		
		this.gameMemo = gameMemo;
	}
	
	public boolean isGameIsMemo() {
		return gameIsMemo;
	}

	public void setTag(String tagName,String tagValue){
		
		tagName = tagName.trim();
		tagValue = this.getString(tagValue.trim());
		
		if(tagValue == null || "".equals(tagValue)){
			return;
		}
		
		if("品牌".equals(tagName)){
			this.gameFactory = tagValue;
		}
		
		else if("发售日期".equals(tagName)){
			if(tagValue.length()!=10){
				this.gameDate = "1000-01-01";
			}else{
				this.gameDate = tagValue;
			}			
		}
		
		else if("原画".equals(tagName)){
			this.gamePic = tagValue;
		}
		
		else if("剧本".equals(tagName)){
			this.gameWriter = tagValue;
		}
				
		else if("TAG".equals(tagName)){
			this.gameTags = tagValue;
		}
		
		else if("介绍".equals(tagName) && "有".equals(tagValue)){
			this.gameIsMemo = true;
		}
		
		else if("声优".equals(tagName)){
			this.gameCast = tagValue;
		}
		
		else if("又名".equals(tagName)){
			this.gameOtherName = tagValue;
		}
		
		else if("音乐".equals(tagName)){
			this.gameMusic = tagValue;
		}
		
		else if("歌手".equals(tagName)){
			this.gameSinger = tagValue;
		}
		
	}
	
	protected String getString(String src){
		return src.replaceAll("'", "’")
				  .replaceAll("\"", "”")
				  .replaceAll("&nbsp;", "")
				  .replaceAll("<br>", "")
				  .replaceAll("<br/>", "")
				  .replaceAll("<p>", "")
				  .replaceAll("</p>", "");
	}
	
	/**
	 * 插入数据库
	 */
	public void insert(){
		
		DBOfflineManager.getDBManager().executeUpdate("insert into ${schema}.LEO_HGAMECN_INFO "
				+ "(GAME_ID,GAME_NAME,GAME_FACTORY,GAME_DATE,GAME_PICTOR,GAME_WRITER,GAME_TAG,GAME_MEMO,GAME_URL,"
				+ "GAME_CAST,GAME_MUSIC,GAME_NAME_OTH,GAME_SINGER) values "
				+ "('"+System.currentTimeMillis()+""+MathUtil.random(3)+"','"+this.gameName+"','"+this.gameFactory+"',to_date('"+this.gameDate+"','yyyy-mm-dd'),"
				+ "'"+this.gamePic+"','"+this.gameWriter+"','"+this.gameTags+"','"+this.gameMemo+"','"+this.gameUrl+"',"
						+ "'"+this.gameCast+"','"+this.gameMusic+"','"+this.gameOtherName+"','"+this.gameSinger+"')");
		
	}
	
}
